package com.nuaa.shopping.dao.impl;

import java.util.List;

import com.nuaa.shopping.dao.ProductDao;
import com.nuaa.shopping.entity.Product;
import com.nuaa.shopping.mapper.ProductMapper;
import com.nuaa.shopping.util.JdbcTemplate;
import com.nuaa.shopping.util.RowMapper;

public class ProductDaoImpl implements ProductDao{

	private RowMapper<Product> rm  = new ProductMapper();
	
	@Override
	public List<Product> selectAll() {
		String sql = new StringBuffer()
			.append(" select ")
			.append(" 	* ")
			.append(" from ")
			.append(" 	t_product ")
			.toString();
		return JdbcTemplate.query(sql, rm);
	}
	
	@Override
	public Product selectById(int id) {
		String sql = new StringBuffer()
		.append(" select ")
		.append(" 	* ")
		.append(" from ")
		.append(" 	t_product ")
		.append(" where ")
		.append(" 	id=? ")
		.toString();
	return JdbcTemplate.queryForObject(sql, rm, id);
	}

}
